[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
Turbo Pascal Statements
If - Conditional Statement
The If expression must evaluate to a standard boolean type value. The
statement following the reserved word, Then is executed if the result
of the expression is TRUE. If the expression evaluates to FALSE, and
the else part is present, the statement following Else is executed.
If the expression evaluates to FALSE, and there is no else part present,
nothing is executed.
NOTE: An Else is usually associated with the closest If that is not
already associated with an Else. You can use Begin and End
to avoid confusion as shown in the example.
+------------+ +-----------+ +-----------+
If --.| expression |--. Then --.| statement |--. Else --.| statement |-.
+------------+ +-----------+ +-----------+
EXAMPLE: Var
x, y : Integer;
Begin
ReadLn(x);
ReadLn(y);
If (x < y) Then
Begin
if (x > 0) Then
WriteLn('x is less than y');
End (* no ; here... *)
Else
Begin
Write('x is equal to ');
WriteLn('or greater than y');
End; (* ; goes here to end If *)
End.
See Also:
Boolean
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson